﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : FlyItem
{
    public bool m_Pierce = false;
    public override void Start()
    {
    }

    // Update is called once per frame
    public override void Update()
    {
        base.Update();
        if (UtilsGame.IsOnline() && !UtilsGame.IsServer(gameObject))
        {
            return;
        }
        if (Death)
            return;
        transform.rotation = Quaternion.FromToRotation(Vector3.up, FlyDirection);
        var moveOffset = FlyDirection * (FlyVelocity * Time.deltaTime);
        Life -= moveOffset.magnitude;
        transform.position += moveOffset;
    }

    override protected void OnTriggerEnter2D(Collider2D collision)
    {
        if (UtilsGame.IsOnline() && !UtilsGame.IsServer(gameObject))
        {
            return;
        }
        if (!m_Pierce)
        {
            base.OnTriggerEnter2D(collision);
        }
        else
        {
            if(m_Ship == null || 
                UtilsGame.IsOfShips(m_Ship.GetComponent<Ship>(), collision.gameObject))
            {
                if (UtilsGame.IsOnline() && UtilsGame.IsServer(gameObject))
                    RpcOnBoomEffect(transform.position);

                BoomEffect();
                CalcDamage(collision, m_Ship, Damage, WeaponType);
            }
        }
    }

}
